package psn.hui.sys.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import psn.hui.sys.domain.News;
import psn.hui.sys.mapper.NewsMapper;
import psn.hui.sys.service.NewsService;
import psn.hui.sys.utils.DataGridView;
import psn.hui.sys.vo.NewsVo;

/**
 * 	系统公告服务接口实现类
 * @author hui
 *
 */
@Service
public class NewsServiceImpl implements NewsService {
	
	@Autowired
	private NewsMapper newsMapper;
	/**
	 * 	条件查询公告列表
	 */
	@Override
	public DataGridView queryAllNews(NewsVo newsVo) {
		Page<Object> page = PageHelper.startPage(newsVo.getPage(), newsVo.getLimit());
		List<News> allNews = newsMapper.queryAllNews(newsVo);
		return new DataGridView(page.getTotal(), allNews);
	}
	/**
	 * 	添加系统公告
	 */
	@Override
	public int addNews(News news) {
		return newsMapper.insertSelective(news);
	}
	/**
	 * 	修改系统公告
	 */
	@Override
	public int updateNews(News news) {
		return newsMapper.updateByPrimaryKeySelective(news);
	}
	/**
	 * 	删除系统公告
	 */
	@Override
	public int deleteNewsById(Integer id) {
		return newsMapper.deleteByPrimaryKey(id);
	}
	/**
	 * 	批量删除系统公告
	 */
	@Override
	public int batchDeleteNewsByIds(Integer[] ids) {
		int rs = 0;
		for (Integer id : ids) {
			rs += newsMapper.deleteByPrimaryKey(id);
		}
		return rs;
	}
	/**
	 * 	根据id获取公告
	 * @param id
	 * @return
	 */
	public News loadNewsById(Integer id) {
		return newsMapper.selectByPrimaryKey(id);
	}
}
